﻿using System;
using Zeus.Thunder.Core;

namespace SharpTrainer.Event
{
    class StockEventTest : ITestCase
    {
        public void Run()
        {
            Stock stock = new Stock("THPW");
            stock.Price = 27.10M;
            // Register with the PriceChanged event
            stock.PriceChanged += stock_PriceChanged;
            //stock.Price = 31.59M;
            stock.Price = 20.59M;
            stock.Price = 26M;
            stock.Price = 27M;
            stock.Price = 25M;
            stock.Price = 28M;
            stock.Price = 28M;
        }

        static void stock_PriceChanged(object sender, PriceChangedEventArgs e)
        {
            decimal percent = 0;
            
            percent = Math.Abs(Math.Round((e.NewPrice - e.LastPrice) * 100 / e.LastPrice, 2)); 

            if (e.NewPrice - e.LastPrice > 0)
            {
                Console.WriteLine("-------------- Stock News --------------");
                Console.WriteLine("Good News: {0}% stock price increase!", percent);
                Console.WriteLine("{0} ---> {1}", e.LastPrice, e.NewPrice);
                Console.WriteLine("----------------------------------------");
                Console.WriteLine();
            }
            else if (e.NewPrice - e.LastPrice == 0)
            {
                Console.WriteLine("Stock price not changed!");
                Console.WriteLine("{0}", e.LastPrice);
                Console.WriteLine();
            }
            else
            {
                Console.WriteLine("-------------- Stock News --------------");
                Console.WriteLine("Bad News: {0}% stock price decrease!", percent);
                Console.WriteLine("{0} ---> {1}", e.LastPrice, e.NewPrice);
                Console.WriteLine("----------------------------------------");
                Console.WriteLine();
            }   
        }
    }
}



